/// 日志数据模型
/// 表示一个用户日志
class DiaryEssence {
  final String id;
  final String userId;
  final String contentType; // 'image' 或 'video'
  final String media; // 图片路径或视频路径
  final String? coverImage; // 视频封面图，图片类型为null
  final String detail; // 详情文字
  final DateTime createTime;

  DiaryEssence({
    required this.id,
    required this.userId,
    required this.contentType,
    required this.media,
    this.coverImage,
    required this.detail,
    required this.createTime,
  });

  /// 从Map创建DiaryEssence
  factory DiaryEssence.fromMap(Map<String, dynamic> map) {
    return DiaryEssence(
      id: map['id'] as String,
      userId: map['userId'] as String,
      contentType: map['contentType'] as String,
      media: map['media'] as String,
      coverImage: map['coverImage'] as String?,
      detail: map['detail'] as String,
      createTime: DateTime.parse(map['createTime'] as String),
    );
  }

  /// 转换为Map
  Map<String, dynamic> toMap() {
    return {
      'id': id,
      'userId': userId,
      'contentType': contentType,
      'media': media,
      'coverImage': coverImage,
      'detail': detail,
      'createTime': createTime.toIso8601String(),
    };
  }

  /// 复制并修改部分属性
  DiaryEssence copyWith({
    String? id,
    String? userId,
    String? contentType,
    String? media,
    String? coverImage,
    String? detail,
    DateTime? createTime,
  }) {
    return DiaryEssence(
      id: id ?? this.id,
      userId: userId ?? this.userId,
      contentType: contentType ?? this.contentType,
      media: media ?? this.media,
      coverImage: coverImage ?? this.coverImage,
      detail: detail ?? this.detail,
      createTime: createTime ?? this.createTime,
    );
  }
}
